<%@ page contentType="text/html;charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>客户类型管理</title>
<%@ include file="/common/meta.jsp"%>
<%@ include file="/common/import.jsp"%>

<script>
		var orgId='${org.orgId}';
		var customerId='${customerId}';
		$(function(){
			$('#customerType').datagrid({
				title:'客户类型信息列表',
				iconCls:'icon-ok',
				fitColumns:true,
				nowrap:false,
				singleSelect:true,
				rownumbers:true,
				animate:true,
				collapsible:true,
				pagination:true,
				pageSize:15,
				pageList:[15,20,30],
				url:'${ctx}/crm/apply/list!data.action?filter_customerId='+customerId+'&dd='+new Date().getTime(),
				idField:'relationId',
				columns:[[
	                 {field:'customerName',title:'客户名称',width:100},
	                 {field:'customerType',title:'客户类型',width:100,
		                  formatter:function(value){
							if('faren'==value){
								return '法人(其它组织)';
							}else if('ziranren'==value){
								return '自然人';
							}else{
							    return '';
							}
		                  }
		             },			 
	                 {field:'customerTypeName',title:'类别名称',width:100},	
	                 {field:'status',title:'申请状态',width:100,
	                 	formatter:function(value){
							if('1'==value){
								return '审核通过';
							}else{
							    return '待审核';
							}
		                  }
	                 },	
	                 {field:'relationId',title:'操作',width:80,
						formatter:function(value,rowData,rowIndex){
							var val = "";
							if("0" == rowData.status){
								val = "<a href='#' onclick='audit(\"" +value+ "\")'>审核通过</a>";
							}
		                	return val;
		                }
		             }
				]]	
				,
				toolbar:[					
		          {
		              	text:'增加',
			              iconCls:'icon-add',
			              handler:function(){save();}
		          }
		          ,'-',
		          {
		              text:'删除',
		              iconCls:'icon-cut',
		              handler:function(){del();}
		          }
		          ,'-',
		          {
		              text:'刷新',
		              iconCls:'icon-reload',
		              handler:function(){
		                  reload();
		             }
		          }
		        ]			
			});
		});	

	
		//查询
		 function searchList(){			
	    	var queryParams = $('#customerType').datagrid('options').queryParams;	    
	       	var opt = $('#customerType').datagrid('options'); 
	        $('#customerType').datagrid('options').pageNumber=1;
	        queryParams["filter_status"] = $('#statusStr').val();
	        queryParams["filter_customerName"] = $('#customerNameStr').val();
	        queryParams["filter_customerId"] = customerId;
	        $('#customerType').datagrid('reload');
	        var page = $('#customerType').datagrid('getPager');
			page.pagination({pageNumber:1,pageSize:opt.pageSize});
		 }
		 //清除查询
		 function clearSearch(){					
		    $('#customerNameStr').val('');
		    $('#statusStr').val('');
		 }
		 
		 //保存
		function save(){
			$('#userAddFrame').html('');
			var url = '${ctx}/crm/addRelat.action?customerId='+customerId;
			$('#userAddFrame').attr("src",url);
			$('#userAddWin').window('setTitle',"添加");	
			$('#userAddWin').window('open');				
		}
		
		//审核方法
		function audit(relationId){
			$.messager.confirm('确认','确定审核通过吗?',function(flag){  
			   if(flag){  
			      $.ajax({
				  url: '${ctx}/crm/apply/audit.action',
				  type: 'POST',
				  cache: false,
				  data: 'relationId='+relationId+'&&status=1',
				  success: function(data){
				  	var oTxt = jQuery.parseJSON(data);
				    var mess = oTxt.msg;	
					var flag = oTxt.flag;
			        if(flag=="T"){
						$.messager.alert('提示',mess, 'info',function(){
						   reload();
						});
					}else{
						$.messager.alert('提示',mess, 'error');
					}
				  }
				});
			   }  
			});
		  }
		
		 //删除方法
		function del(){
			var obj = getSelected();
			if(obj){
				$.messager.confirm('确认','确定要删除: <font color=red><b>'+obj.customerTypeName+'</b></font> ?',function(flag){  
			        if(flag){  
			            $.ajax({
						  url: '${ctx}/crm/relatDel.action',
						  type: 'POST',
						  cache: false,
						  data: 'relationId='+obj.relationId,
						  success: function(data){
						  	var oTxt = jQuery.parseJSON(data);
						    var mess = oTxt.msg;	
							var flag = oTxt.flag;
					        if(flag=="T"){
								$.messager.alert('提示',mess, 'info',function(){
								   reload();
								});
							}else{
								$.messager.alert('提示',mess, 'error');
							}
						  }
						});
			        }  
			     });
			  }
		  }
		
		//重新加载数据
		function reload(){
			$('#customerType').datagrid('reload');
		}
		  
		  //取得数据
		  function getSelected(){
		  	var rec = $('#customerType').datagrid('getSelected');
		  	if(rec){
		  		return rec;
		  	}else{
		  		$.messager.alert('提示',"请选择需要操作记录!", 'info');
		  		return null;
		  	}
		  }
		  
		   //关闭win
		 function closeWin(){
		 	$('#userAddWin').window('close');	
		 }
		
	     
	</script>
</head>
<body>
	<div id="tab_search">
		<table id="customerType"></table>
		<div id="userAddWin" class="easyui-window" title="客户信息"
			style="padding:5px;width:500px;height:250px;" align="center"
			iconCls="icon-search" closed="true" maximizable="false"
			minimizable="false" collapsible="false">
			<iframe frameborder="0" id="userAddFrame" height="100%" width="100%"
				scrolling="yes" frameborder="0"></iframe>
		</div>
</body>
</html>